<template>
  <div>
    <div>
      <el-form :inline="true" size="medium">
        <!-- <el-form-item clearable label="审核状态：">
          <el-select v-model="queryObj.audit_status" placeholder="全部">
            <el-option
              v-for="(item, key) in statusList"
              :key="key"
              :label="item"
              :value="key"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item clearable label="拼购状态：">
          <el-select v-model="queryObj.group_purchase_type" placeholder="全部">
            <el-option
              v-for="(item, key) in typeList"
              :key="key"
              :label="item"
              :value="key"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="拼购名称：">
          <el-input placeholder="请输入拼购名称" v-model="queryObj.query_value">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getMainListReset"
            ><i class="iconfont icon-search"></i>查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="mytable">
      <el-table
        :data="mainList"
        tooltip-effect="dark"
        stripe
        style="width: 100%"
      >
        <el-table-column label="拼购ID" prop="gp_id">
        </el-table-column>
        <el-table-column
          label="拼购名称"
          show-overflow-tooltip
          prop="group_purchase_name"
        >
        </el-table-column>
        <el-table-column width="100" label="拼购价">
          <template slot-scope="scope">
            {{ scope.row.group_purchase_price }}
          </template>
        </el-table-column>
        <el-table-column label="成团人数" prop="user_count"> </el-table-column>
        
        <el-table-column width="120">
          <template slot="header">
            <span>成人利润（元）</span>
          </template>
          <template slot-scope="scope">
            {{ scope.row.cb_price_lr }}
          </template>
        </el-table-column>
        <el-table-column width="120">
          <template slot="header">
            <span>儿童利润（元）</span>
          </template>
          <template slot-scope="scope">
            {{ scope.row.child_cb_price_lr }}
          </template>
        </el-table-column>
        <el-table-column label="审核状态">
          <template slot-scope="scope">
            <p>{{ statusList[scope.row.audit_status] }}</p>
          </template>
        </el-table-column>
        <el-table-column label="拼购时间">
          <template slot-scope="scope">
            {{ scope.row.start_time | formatDate('yyyy-MM-dd hh:mm:ss') }} ---- {{ scope.row.end_time | formatDate('yyyy-MM-dd hh:mm:ss') }}
          </template>
        </el-table-column>
        <el-table-column label="拼购状态">
          <template slot-scope="scope">
            {{ typeList[scope.row.group_purchase_status] }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="text" @click="golook(scope.row)"
              >查看</el-button
            >
            <el-button type="text" @click="shenheOpen(scope.row)"
              >审核</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagecon"
        background
        layout="total, sizes, prev, pager, next"
        @current-change="_mainList"
        @size-change="_mainList"
        :page-size.sync="page.limit"
        :page-sizes="pageSizeArr"
        :current-page.sync="page.page"
        :total="page.total"
      >
      </el-pagination>
    </div>

    <el-dialog title="商品审核" :visible.sync="dialogFormVisible">
      <el-form ref="addForm" :model="addForm" :rules="rules" label-width="120px">
        <el-form-item label="线路名称：" >
          {{addForm.name}}
        </el-form-item>
        <el-form-item label="审核状态：" prop="audit_status">
          <el-radio-group v-model="addForm.audit_status">
            <el-radio v-for="(item, key) in statusList2" :key="key" :label="key">{{item}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="反馈详情："  prop="remark">
          <el-input type="textarea" placeholder="请输入" :rows="4" v-model="addForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="doAction">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getGroupPurchaseList,
  auditGroupPurchase
} from 'api/marketingManagement/groupBuying';
import { line_audit_status, line_status } from 'common/config/constConfig';
import { pageSizeArr } from 'common/config/constConfig';
import config from 'api/config';

export default {
  components: {},
  computed: {},
  data() {
    return {
      statusList: line_audit_status,
      lineStatus: line_status,
      dialogMode: 'add',
      addForm: {},
      statusList2: {
        2: '通过',
        4: '不通过'
      },
      typeList: {
        0: '未开始',
        1: '进行中',
        2: '已结束'
      },
      showList: {
        1: '显示',
        0: '不显示'
      },
      auditList: [],
      rules: {
        audit_status: [
          { required: true, message: '请选择状态', trigger: 'blur' }
        ],
        remark: [
          { required: true, message: '请输入原因', trigger: 'blur' }
        ]
      },
      imgUrl: config.imgUrl,
      dialogFormVisible: false,
      pageSizeArr,
      queryObj: {
        audit_status: 3
      },
      mainList: [],
      seriesList: [],
      page: {
        total: 0,
        page: 1,
        limit: 10
      }
    };
  },
  methods: {
      // 审核
    shenheOpen(row) {
      this.addForm = {}
      this.dialogFormVisible = true
      this.addForm.gp_id = row.gp_id
      this.$set(this.addForm, 'name', row.group_purchase_name)
    },
    async doAction() {
      await this.$refs.addForm.validate();
      let data = { ...this.addForm };
      await auditGroupPurchase(data)
      this._caozuoAfter('审核成功')
    },
    golook(row) {
      this.$router.push({
        path: '/home/groupBuyingAdd',
        query: { id: row.gp_id, type: 'look' }
      });
    },
    _caozuoAfter(msg) {
      this.dialogFormVisible = false;
      this.$message({
        message: msg,
        type: 'success'
      });
      this._mainList();
    },
    getMainListReset() {
      this.page.page = 1;
      this._mainList();
    },
    changeMoney(arr) {
      arr.forEach(item => {
        item.cb_price_lr = (item.group_purchase_price - item.cb_price) / 100;
        item.child_cb_price_lr = (item.group_purchase_price - item.child_cb_price) / 100;
        item.group_purchase_price /= 100;
      });
      return arr;
    },
    // 获取
    _mainList() {
      let data = { ...this.queryObj };
      data.pageInfo = { ...this.page };
      getGroupPurchaseList(data).then(res => {
        let pageInfo = res.pageInfo;
        this.page.total = pageInfo.Total;
        this.page.page = pageInfo.page;
        this.mainList = this.changeMoney(res.rData);
      });
    },
  },
  created() {
    this._mainList();
  }
};
</script>

<style lang="scss" scoped></style>
